package com.mairuide._frame.utils;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

/**
 * Created by 敲代码的卡卡罗特
 * on 2018/12/20 10:35.
 */
public class CalendarUtils {
    /**
     *
     * @author 刘中华
     * @date 2018/12/20 11:01
     * @param [beginTime, endTime]
     * @return java.util.List<java.lang.String>
     * @Description  得到一个时间段的集合
     */
    public static List<String> getDateSlot(String beginTime,String endTime){
        ArrayList<String> list = new ArrayList<>();
        list.add(beginTime);
        String temp=beginTime;
        while(isBig(temp,endTime)){
            temp = getNextDay(temp);
            list.add(temp);
        }
        return list;
    }
    /**
     *
     * @author 刘中华
     * @date 2018/12/20 10:55
     * @param [time]
     * @return java.lang.String
     * @Description  得到下一天
     */
    public static String getNextDay(String time){
        Date date = null;
        SimpleDateFormat sdf= new SimpleDateFormat("yyyy-MM-dd");
        Calendar calendar = Calendar.getInstance();
        try {
            date = sdf.parse(time);
            calendar.setTime(date);
            calendar.add(Calendar.DAY_OF_MONTH,1);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return sdf.format(calendar.getTime());
    }

    /**
     *
     * @author 刘中华
     * @date 2018/12/20 10:42
     * @param [beginTime, endTime]
     * @return boolean
     * @Description 判断两个时间那个大
     */
    public static boolean isBig(String beginTime,String endTime){
        Date date1 = null;
        Date date2 = null;
        try {
            SimpleDateFormat sdf= new SimpleDateFormat("yyyy-MM-dd");
            date1 = sdf.parse(beginTime);
            date2 = sdf.parse(endTime);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return date1.getTime()<date2.getTime();
    }
}
